package com.example.myapplication;


import android.net.Uri;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.VideoView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;

import java.util.List;

public class PopRecyclerAdapter extends RecyclerView.Adapter<PopRecyclerAdapter.ViewHolder> {
    private List<String> PersonList;


    public PopRecyclerAdapter(List<String> PersonList)
    {
        this.PersonList = PersonList;

    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View itemView = LayoutInflater.from(parent.getContext()).inflate(R.layout.pop_item, parent, false);

        ViewHolder viewHolder = new ViewHolder(itemView);
        return viewHolder;
    };

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, final int position) {


//       // holder.id.setText(String.valueOf(Formatter.formatFileSize(PersonList.get(position).getSize())));
//        holder.name.setText(PersonList.get(position).getName());
//        holder.num.setText(PersonList.get(position).getName());
//        //holder.action.setText(PersonList.get(position).getAction());
//
//        Glide.with(holder.imageView.getContext())
//                .load(PersonList.get(position).getPath())
//                .into(holder.imageView);
//      //  holder.imageView.setImageBitmap(PersonList.get(position).getBitmap());
        holder.name.setText(PersonList.get(position).toString());

        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (listener != null) {
                    listener.onClick(position);
                }
            }
        });

    }

    @Override
    public int getItemCount() {
        return PersonList.size();
    }

    class ViewHolder extends RecyclerView.ViewHolder {
        TextView name,num;


        ImageView imageView;
        RelativeLayout rv;

        public ViewHolder(@NonNull View itemView)
        {

            super(itemView);
            this.imageView= itemView.findViewById(R.id.pop_iv);
            this.name= itemView.findViewById(R.id.pop_name);
            this.num= itemView.findViewById(R.id.pop_num);

        }

    }


    //第一步 定义接口
    public interface OnItemClickListener {
        void onClick(int position);
    }

    private OnItemClickListener listener;

    //第二步， 写一个公共的方法
    public void setOnItemClickListener(OnItemClickListener listener) {
        this.listener = listener;
    }
}